<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>login</title>
    <meta http-equiv="Content-Type" charset="UTF-8">
    <link rel="stylesheet" href="../../static/css/font.css">
    <link rel="stylesheet" href="../../static/css/xadmin.css">
    <link rel="stylesheet" href="../../static/css/snow.css">
    <link rel="stylesheet" href="../../static/css/style.css">
    <link rel="stylesheet" href="../../static/css/font-awesome.min.css">
    <script src="../../static/js/jquery.min.js" type="text/javascript"></script>
    <script src="../../static/lib/layui/layui.js" type="text/javascript"></script>
    <script src="../../static/js/xadmin.js" type="text/javascript"></script>
</head>

<body>
<div class="snow-container">
    <div class="snow foreground"></div>
    <div class="snow foreground layered"></div>
    <div class="snow middleground"></div>
    <div class="snow middleground layered"></div>
    <div class="snow background"></div>
    <div class="snow background layered"></div>
</div>

<div class="top-buttons-agileinfo">
    <a href="/login" class="active">登录</a><a href="/register" >注册</a>
</div>
<h1>学海无涯线上图书馆</h1>
<div>dada</div>
<div class="main-agileits" id="loginApp">
    <!--form-stars-here-->
    <div class="form-w3-agile">
        <h2 class="sub-agileits-w3layouts">登录</h2>
        <form action="#" method="post">
            <input type="text" placeholder="用户名" id="username"/>
            <input type="password" placeholder="密码" id="password" />
            <button type="button" class="layui-btn layui-btn-lg layui-btn-normal" onclick="login()">登录</button>
            <p class="p-bottom-w3ls"><a href="/register.jsp" >Sign Up here</a>if u do not have an account yet.</p>
        </form>
    </div>
</div>
<!--//form-ends-here-->
<!-- copyright -->
<div class="copyright w3-agile">
    <p> © 2017 Internship Sign In & Sign Up Form . All rights reserved | Design by <a href="https://shop585798004.taobao.com/" target="_blank">前端ui</a></p>
</div>
</body>

<script>
    function login() {
        var username = $("#username").val();
        var password = $("#password").val();

        $.ajax({
            url:"/user/login",
            type:"post",
            data:{username:username,password:password},
            dataType:"json",
            success:function (rs) {
                console.log(rs)
                if (rs.code == 200){
                    layer.alert(rs.msg,{icon:6},function () {
                        if (rs.data.role.length > 1){
                            location.href = "/manage-index"
                        }else {
                            location.href = "/user-index"
                        }

                    })
                }else {
                    layer.alert(rs.msg,{icon:5},function () {
                        location.reload();//重新加载
                    })
                }
            },
            error:function () {
                alert("服务器异常！！！")
            }
        })
    }
</script>
</html>